package com.sun.draw.command;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.draw.api.AbstractDrawCommand;
import com.sun.draw.api.IDrawCommand;
import com.sun.draw.param.DrawParamContent;
import com.sun.draw.pojo.InstantDrawInfo;
import com.sun.util.DrawUtils;

public class QueryInstantCommand extends AbstractDrawCommand implements IDrawCommand{

	/**
	 * 日志
	 */
	private Logger logger = LoggerFactory.getLogger(QueryInstantCommand.class);

	public boolean execute(DrawParamContent drawParamContent) {
		try {
			String activityCode = drawParamContent.getActivityCode();
			List<InstantDrawInfo> resList = null;
			if(StringUtils.isNoneBlank(activityCode)) {
				List<InstantDrawInfo> drawList = drawParamContent.getDrawService().queryInstantDrawInfo(activityCode);
				
				if(null != drawList && drawList.size() > 0) {
					resList = new ArrayList<InstantDrawInfo>();
					for (InstantDrawInfo instantDrawInfo : drawList) {
						if(null == instantDrawInfo) {
							continue;
						}
						
						resList.add(instantDrawInfo);
					}
				}
			}
			
			//logger.info("--------->执行排序抽奖策略操作...");
			DrawUtils.sortByProbabilityAsc(resList);
			
			//logger.info("-------->执行设置抽奖策略列表操作...");
			drawParamContent.setInstantDrawInfoList(resList);
		} catch (Exception e) {
			logger.error("查询奖品信息异常....");
			e.printStackTrace();
		}
		
		return true;
	}
}
